home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d13
/
pcrsep89.arc
/
LIFE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-21
|
2KB
|
58 lines
/* Sample C program that John Conway's Game of Life.
* Use either Small or Medium memory model
*
* Save as: Life.C
* Compile Quick C: QCL -W3 LIFE.C CA.OBJ
* MSC: CL -W3 LIFE.C CA.OBJ
* Turbo C: TCC -w LIFE.C CA.OBJ
*/
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include "ca2.h"
#define LIVE 64 /* Display attributes for */
#define DEAD 0 /* "living" & "dead" cells */
void main(void)
{
cainit(4,ca_array); /* Use 80x25 CGA text mode */
caset(12,40,LIVE); /* Starting universe -- one of */
caset(12,41,LIVE); /* many, many possible choices. */
caset(13,39,LIVE);
caset(13,40,LIVE);
caset(14,40,LIVE);
cashow(); /* Display the starting world */
while(!kbhit()) /* Until the user presses a key */
cagen(); /* create & display next generation */
getch(); /* Remove waiting keystroke */
careset(); /* Tidy up */
exit(0); /* Return to DOS */
}
int far pascal cacell() /* Here's where we do the work */
{
int i, count=0, result;
for(i = NorthWest; i <= SouthEast; i++) /* Count the neighbors */
count += (ca_array[i] == LIVE);
count -= (ca_array[Self] == LIVE); /* but not yourself */
if (count == 2) /* If 2 neighbors */
result = ca_array[Self]; /* don't change */
else if (count == 3) /* If 3 neighbors */
result = LIVE; /* come alive */
else /* Otherwise die of */
result = DEAD; /* loneliness or crowding */
return result;
}